package com.openbravo.pos.util;

import com.openbravo.beans.JPasswordDialog;
import com.openbravo.pos.forms.AppLocal;
import java.awt.Component;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class Hashcypher
{
  public static boolean authenticate(String paramString1, String paramString2)
  {
    if ((paramString2 == null) || (paramString2.equals("")) || (paramString2.startsWith("empty:")))
      return (paramString1 == null) || (paramString1.equals(""));
    if (paramString2.startsWith("sha1:"))
      return paramString2.equals(hashString(paramString1));
    if (paramString2.startsWith("plain:"))
      return paramString2.equals("plain:" + paramString1);
    return paramString2.equals(paramString1);
  }

  public static String hashString(String paramString)
  {
    if ((paramString == null) || (paramString.equals("")))
      return "empty:";
    try
    {
      MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
      localMessageDigest.update(paramString.getBytes("UTF-8"));
      byte[] arrayOfByte = localMessageDigest.digest();
      return "sha1:" + StringUtils.byte2hex(arrayOfByte);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      return "plain:" + paramString;
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
    }
    return "plain:" + paramString;
  }

  public static String changePassword(Component paramComponent)
  {
    String str1 = JPasswordDialog.showEditPassword(paramComponent, AppLocal.getIntString("Label.Password"), AppLocal.getIntString("label.passwordnew"), new ImageIcon(Hashcypher.class.getResource("/com/openbravo/images/password.png")));
    if (str1 != null)
    {
      String str2 = JPasswordDialog.showEditPassword(paramComponent, AppLocal.getIntString("Label.Password"), AppLocal.getIntString("label.passwordrepeat"), new ImageIcon(Hashcypher.class.getResource("/com/openbravo/images/password.png")));
      if (str2 != null)
      {
        if (str1.equals(str2))
          return hashString(str1);
        JOptionPane.showMessageDialog(paramComponent, AppLocal.getIntString("message.changepassworddistinct"), AppLocal.getIntString("message.title"), 2);
      }
    }
    return null;
  }

  public static String changePassword(Component paramComponent, String paramString)
  {
    String str = JPasswordDialog.showEditPassword(paramComponent, AppLocal.getIntString("Label.Password"), AppLocal.getIntString("label.passwordold"), new ImageIcon(Hashcypher.class.getResource("/com/openbravo/images/password.png")));
    if (str != null)
    {
      if (authenticate(str, paramString))
        return changePassword(paramComponent);
      JOptionPane.showMessageDialog(paramComponent, AppLocal.getIntString("message.BadPassword"), AppLocal.getIntString("message.title"), 2);
    }
    return null;
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.util.Hashcypher
 * JD-Core Version:    0.6.0
 */